<?php
//require_once 'application/modules/admin/models/monhoc.php';
/**
 * 
 * Form tao moi bai kiem tra
 * @author Vo Xuan Hoan
 *
 */
class Admin_Form_QuizForm extends Zend_Form{
	
	private $auth; //has login
	private $manager; // obj of quanly table

    public function init(){
    
    	//
    	// === Get info had Login
    	$this->auth	= Zend_Auth::getInstance()->getIdentity();
    	
    	$this->manager = new Admin_Model_Manages();
    	//
    	// === Tao form
        $this->setMethod('post');
        $this->setAttrib('class', 'validate-form');
        
        $this->addElement('select','cbbLop[]',array(
       							'label'			=>	'Lớp',
        						'class'			=>	'required',
        						'multiple'		=>	'multiple',
       							'multiOptions'	=>	$this->getLop()
       						)
       			);
        $this->addElement('select','cbbMon',array(
       							'label'			=>	'Môn học',
       							'multiOptions'	=>	$this->getMon()
       						)
       			);
       	$this->addElement('select','cbbHocKy',array(
       					'label'			=>	'Học kỳ',
       					'multiOptions'	=>	array(
       						'1'			=>	'Học kỳ 1',
       						'2'			=>	'Học kỳ 2',
       					))
       			);
        $this->addElement('text','txtName',array(
        			'label'			=>	'Tên',
        			'class'			=>	'required',
        			'required'		=>	true
        		));
        	
        $this->addElement('text','txtTime',array(
        			'label'			=>	'Thời gian (phút)',
        			'required'		=>	true,
        			'class'			=>	'required number'
        			
        		));
       	$this->addElement('text','txtTotalNumQuestion',array(
       				'label'			=>	'Tổng số câu hỏi của bài test',
       				'class'			=>	'required number',
       				'required'		=> true
       			));
       	
        
       	$this->addElement('text','txtDateStartD',
       		array(
       			'label'		=>	'Ngày bắt đầu',
       			'class'		=>	' required',
       		)
       	);
       	$this->addElement('text','txtDateStartH',
       		array(
       			'class'		=>	'hours required',
       			'required'	=>	true,
       			'label'		=>	'Giờ bắt đầu (exp: 10h30)'
       		)
       	);
       	
       	
       	$this->addElement('text','txtDateEndD',array(
       				'label'			=> 'Ngày kết thúc',
       				'required'		=>	TRUE,
       				'class'			=>	'required'
       	));
       	$this->addElement('text','txtDateEndH',array(
       				'required'		=>	TRUE,
       				'label'			=>	'Giờ kết thúc (exp: 10h30)',
       				'class'			=>	'hours required',
       	));
       	
       	$this->addElement('select','cbbHeSo',array(
       							'label'			=>	'Hệ số điểm cho môn',
       							'multiOptions'	=>	array(
       								'1'			=>	'Hệ số 1',
       								'2'			=>	'Hệ số 2',
       								'3'			=>	'Điểm thi'
       							)
       						)
       			);
       	
       	
    }

     /**
     * 
     * Them Action vao trong form
     * @param unknown_type $action : action se thuc thi trong form
     */
    function addAction($action){
    	$this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl().'/admin/quiz/'.$action);
    }
    
 	/* Add nut submit 
     */
    function addSubmitButton($name, $label){
    	$this->addElement('submit',$name,array(
    						'label'		=>	$label,
    						'decorators'=>	array('ViewHelper',array('HtmlTag',array(
    																			'tag' => 'dd' //giu nguyen the dd ko them bat cu the j
    																		)
    														
    															)
    							
    										),
    						'class'		=>	'input-hover uSubmit'	
    					));
    	
    }
    
	function addHiddenId($name,$value){
    	$this->addElement('hidden',$name,array(
			    				'value'	=> $value	
    						));
    }
    
    private function getMon(){
    	if ($this->auth->quyen == "admin"){
    		$mon = new Admin_Model_Monhoc();
    		$monHoc = $mon->fetchAllMonHoc();
    	}else {
    		$monHoc = $this->manager
    					->selectManager("u.username = '".$this->auth->username."'")
    					->query()->fetchAll();
    	}
    	
    	$arrData = array();
    	foreach ($monHoc as $value) {
    		$arrData[$value['id']] =$value['tenMonHoc']	;
    	}
    	return $arrData;
    }
    
    /**
     * 
     * Get info of lop table
     */
	private function getLop(){
		
		if ($this->auth->quyen == "admin"){
			$lop = new Admin_Model_Lops();
			$lopArr = $lop->getAllLop()->toArray();
		}else{
    		$lopArr = $this->manager->selectManager("u.username = '".$this->auth->username."'")
    					->query()->fetchAll();	
		}
    	
    	$arrData = array();
    	foreach ($lopArr as $value) {
    		$arrData[$value['id']] =$value['tenLop'];
    	}
    	return $arrData;
    }
}

       	
//       	$this->addElement('text','txtDateStartY',
//       					array('decorators'=>array('ViewHelper','Label')
//       	));
//       	$this->addElement('text','txtDateStartD',
//       		array(
//       			'decorators'=>array('ViewHelper','Label')    			
//       		)
//       	);
//       	
       	
//       	$this->addDisplayGroup(
//       		array('txtDateStartD','txtDateStartM','txtDateStartY'), 
//       		'txtDateStart',
//       		array(
//		        'decorators' => array(
//		            'FormElements',
//		            array('HtmlTag', array('tag' => 'div', 'class' => 'dataStart')),
//		        )
//		    ) 
//       	);

